/**   
 * 文件名：GLClient.java   
 *   
 * 版本信息：   
 * 日期：2013年9月26日   
 * Copyright 足下 Corporation 2013    
 * 版权所有   
 *   
 */
package serv;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.caucho.burlap.io.BurlapInput;
import com.caucho.burlap.io.BurlapOutput;
import com.itrus.cryptorole.CryptoException;
import com.itrus.cryptorole.NotSupportException;
import com.itrus.util.Base64;

/**   
 * 此类描述的是：   桂林财政一体化，龙图客户端接口，传输使用XML burlap协议
 * @author: 朱凯锋   
 * @version: 2013年9月26日 下午5:49:58    
 */

/*conn.setRequestProperty("Content-Type", "text/xml");
conn.setRequestProperty("applicationid", "分配的银行编码");
conn.setRequestProperty("date-type", "业务数据标识");
conn.setRequestProperty("compress-mode", "压缩模式");
conn.setRequestProperty("validatecode", "验证码");
银行系统接入服务地址：/exserver/remoting/bankservice(只适用于公务卡支付凭证查询)*/

public class GLClient {
	private void init() {
		this.billcode = "";
		this.oldbillcode = "";
		this.printid = "";
		this.createdate = "";
		this.paybankaccount = "";
		this.pay = "";
		this.paybank = "";
		this.payeebankaccount = "";
		this.payee = "";
		this.payeebank = "";
		this.departmentname = "";
		this.expfunc = "";
		this.expeco = "";
		this.program = "";
		this.paykind = "";
		this.remark = "";
		this.guid = "";
		this.vouchertype = "";
		this.fundtype = "";
		this.programname = "";
		this.bdgmanagedivision = "";
		this.indsource = "";
		this.profund = "";
		this.cleartag = "";
		this.wfstatus = "";
		this.funcname = "";
		this.bdgagencyname = "";
		this.expecocode = "";
		this.paytypecode = "";
		this.programcode = "";
		this.settlmodecode = "";
		this.expeconame = "";
		this.paybankcode = "";
		this.fundtypename = "";
		this.clearbankname = "";
		this.clearbankcode = "";
		this.departmentcode = "";
		this.funccode = "";
		this.bdgagencycode = "";
		this.sendtime = "";
		this.settlmodename = "";
		this.paytypename = "";
		this.billid = "";
		this.fundtypecode = "";
		this.total = "";
		this.tkreason = "";
		this.tpreason = "";
		this.totalDS = "";
		this.user_id = "";
		this.transtime = "";
		this.orgdate = "";
		this.orgtotal = "";
		this.details = 0;
		this.amt = null;
		this.account = null;
		this.cardname = null;
		this.message = "";
		this.result = "";
	}

	/**   
	 * 创建一个新的实例 GLClient.   
	 *      
	 */
	String billcode = "";
	String oldbillcode="";
	String billtype = "";

	//以下为财厅返回的数据
	String printid = ""; // 凭证编号
	String createdate = ""; // 凭证日期
	String paybankaccount = ""; // 付款人账号
	String pay = ""; // 付款人全称
	String paybank = ""; // 付款人开户银行
	String payeebankaccount = ""; // 收款人账号
	String payee = ""; // 收款人全称
	String payeebank = ""; // 收款人开户行
	String departmentname = ""; // 一级预算单位
	String expfunc = ""; // 支出功能分类
	String expeco = ""; // 支出经济分类
	String program = ""; // 项目
	String paykind = ""; // 支出类型
	String remark = ""; // 摘要
	String guid = ""; // 凭证唯一标识
	String vouchertype = ""; // 凭证类型
	String fundtype = ""; // 资金性质
	String programname = ""; // 项目名称
	String bdgmanagedivision = ""; // 归口处室
	String indsource = ""; // 预算来源
	String profund = ""; // 项目归类
	String cleartag = ""; // 清算标识
	String wfstatus = ""; // 状态标识
	String funcname = ""; // 功能分类科目名称
	String bdgagencyname = ""; // 预算单位名称
	String expecocode = ""; // 支出经济分类
	String paytypecode = ""; // 支付方式编码
	String programcode = ""; // 项目类别编码
	String settlmodecode = ""; // 付款方式编码
	String expeconame = ""; // 支出经济分类
	String paybankcode = ""; // 付款银行编码
	String fundtypename = ""; // 资金性质名称
	String clearbankname = ""; // 清算银行名称
	String clearbankcode = ""; // 清算银行代码
	String departmentcode = ""; // 上级单位编码
	String funccode = ""; // 功能分类科目编码
	String bdgagencycode = ""; // 预算单位编码
	String sendtime = ""; // 最后操作时间
	String settlmodename = ""; // 付款方式名称
	String paytypename = ""; // 支付方式名称
	String billid = ""; // billid
	String fundtypecode = ""; // 资金性质编码
	String reason = ""; // 退款原因
	String total = ""; // 总金额
	//
	String tkreason="";	//<!--退款原因-->
	String tpreason="";	//<!--退票原因-->

	String totalDS="";	//总金额大写
	String user_id="";
	String transtime="";	//交易时间
	
	String orgdate="";	//原凭证日期
	String orgtotal="";	//原凭证金额
	//detail
	int details=0;
	String[] amt = null    	;	//金额
	String[] account = null	;	//卡号
	String[] cardname = null;	//持卡人
	//result
	String message="";
	String result="";
	//---
	private HttpURLConnection conn = null;

	


	/**   
	 * orgdate   
	 *   
	 * @return the orgdate   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getOrgdate() {
		if(orgdate.length()<2)
			VgetOrg();
		return orgdate;
	}

	/**   
	 * orgtotal   
	 *   
	 * @return the orgtotal   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getOrgtotal() {
		if(orgtotal.length()<2)
			VgetOrg();
		return orgtotal;
	}

	/**   
	 * @param billtype the billtype to set   
	 */
	public void setBilltype(String billtype) {
		this.billtype = billtype;
	}
	
	/**   
	 * tkreason   
	 *   
	 * @return the tkreason   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getTkreason() {
		return tkreason;
	}

	/**   
	 * @param tkreason the tkreason to set   
	 */
	public void setTkreason(String tkreason) {
		this.tkreason = tkreason;
	}

	/**   
	 * tpreason   
	 *   
	 * @return the tpreason   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getTpreason() {
		return tpreason;
	}

	/**   
	 * @param tpreason the tpreason to set   
	 */
	public void setTpreason(String tpreason) {
		this.tpreason = tpreason;
	}
	/**   
	 * transtime   
	 *   
	 * @return the transtime   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getTranstime() {
		return transtime;
	}

	/**   
	 * @param transtime the transtime to set   
	 */
	public void setTranstime(String transtime) {
		this.transtime = transtime;
	}

	/**   
	 * @param user_id the user_id to set   
	 */
	public void setUser_id(String user_id) {
		this.user_id = user_id;
	}

	/**   
	 * oldbillcode   
	 *   
	 * @return the oldbillcode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getOldbillcode() {
		return oldbillcode;
	}

	/**   
	 * @param oldbillcode the oldbillcode to set   
	 */
	public void setOldbillcode(String oldbillcode) {
		this.oldbillcode = oldbillcode;
	}

	/**   
	 * totalDS   
	 *   
	 * @return the totalDS   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getTotalDS() {
		return totalDS;
	}

	/**   
	 * departmentcode   
	 *   
	 * @return the departmentcode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getDepartmentcode() {
		return departmentcode;
	}

	/**   
	 * @param departmentcode the departmentcode to set   
	 */
	public void setDepartmentcode(String departmentcode) {
		this.departmentcode = departmentcode;
	}

	/**   
	 * funccode   
	 *   
	 * @return the funccode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getFunccode() {
		return funccode;
	}

	/**   
	 * @param funccode the funccode to set   
	 */
	public void setFunccode(String funccode) {
		this.funccode = funccode;
	}

	/**   
	 * bdgagencycode   
	 *   
	 * @return the bdgagencycode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getBdgagencycode() {
		return bdgagencycode;
	}

	/**   
	 * @param bdgagencycode the bdgagencycode to set   
	 */
	public void setBdgagencycode(String bdgagencycode) {
		this.bdgagencycode = bdgagencycode;
	}

	/**   
	 * sendtime   
	 *   
	 * @return the sendtime   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getSendtime() {
		return sendtime;
	}

	/**   
	 * @param sendtime the sendtime to set   
	 */
	public void setSendtime(String sendtime) {
		this.sendtime = sendtime;
	}

	/**   
	 * settlmodename   
	 *   
	 * @return the settlmodename   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getSettlmodename() {
		return settlmodename;
	}

	/**   
	 * @param settlmodename the settlmodename to set   
	 */
	public void setSettlmodename(String settlmodename) {
		this.settlmodename = settlmodename;
	}

	/**   
	 * paytypename   
	 *   
	 * @return the paytypename   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPaytypename() {
		return paytypename;
	}

	/**   
	 * @param paytypename the paytypename to set   
	 */
	public void setPaytypename(String paytypename) {
		this.paytypename = paytypename;
	}

	/**   
	 * billid   
	 *   
	 * @return the billid   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getBillid() {
		return billid;
	}

	/**   
	 * @param billid the billid to set   
	 */
	public void setBillid(String billid) {
		this.billid = billid;
	}

	/**   
	 * fundtypecode   
	 *   
	 * @return the fundtypecode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getFundtypecode() {
		return fundtypecode;
	}

	/**   
	 * @param fundtypecode the fundtypecode to set   
	 */
	public void setFundtypecode(String fundtypecode) {
		this.fundtypecode = fundtypecode;
	}

	/**   
	 * @param details the details to set   
	 */
	public void setDetails(int details) {
		this.details = details;
	}

	/**   
	 * expecocode   
	 *   
	 * @return the expecocode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getExpecocode() {
		return expecocode;
	}

	/**   
	 * @param expecocode the expecocode to set   
	 */
	public void setExpecocode(String expecocode) {
		this.expecocode = expecocode;
	}

	/**   
	 * paytypecode   
	 *   
	 * @return the paytypecode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPaytypecode() {
		return paytypecode;
	}

	/**   
	 * @param paytypecode the paytypecode to set   
	 */
	public void setPaytypecode(String paytypecode) {
		this.paytypecode = paytypecode;
	}

	/**   
	 * programcode   
	 *   
	 * @return the programcode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getProgramcode() {
		return programcode;
	}

	/**   
	 * @param programcode the programcode to set   
	 */
	public void setProgramcode(String programcode) {
		this.programcode = programcode;
	}

	/**   
	 * settlmodecode   
	 *   
	 * @return the settlmodecode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getSettlmodecode() {
		return settlmodecode;
	}

	/**   
	 * @param settlmodecode the settlmodecode to set   
	 */
	public void setSettlmodecode(String settlmodecode) {
		this.settlmodecode = settlmodecode;
	}

	/**   
	 * expeconame   
	 *   
	 * @return the expeconame   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getExpeconame() {
		return expeconame;
	}

	/**   
	 * @param expeconame the expeconame to set   
	 */
	public void setExpeconame(String expeconame) {
		this.expeconame = expeconame;
	}

	/**   
	 * paybankcode   
	 *   
	 * @return the paybankcode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPaybankcode() {
		return paybankcode;
	}

	/**   
	 * @param paybankcode the paybankcode to set   
	 */
	public void setPaybankcode(String paybankcode) {
		this.paybankcode = paybankcode;
	}

	/**   
	 * fundtypename   
	 *   
	 * @return the fundtypename   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getFundtypename() {
		return fundtypename;
	}

	/**   
	 * @param fundtypename the fundtypename to set   
	 */
	public void setFundtypename(String fundtypename) {
		this.fundtypename = fundtypename;
	}

	/**   
	 * total   
	 *   
	 * @return the total   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getTotal() {
		return total;
	}

	/**   
	 * @param total the total to set   
	 */
	public void setTotal(String total) {
		this.total = AmtFormat(total);
		//同时设金额大写
		char c = total.charAt(0);
		if(c<'0'||c>'9')
			return;
		totalDS = cleanZero(splitNum(roundString(total)));
		if(totalDS.endsWith("元"))
			totalDS += "整";
	}
	/** 
	 * 把已经转换好的中文金额大写形式加以改进，清理这个字 
	 * 符串里面多余的零，让这个字符串变得更加可观 
	 * 注：传入的这个数应该是经过 splitNum() 方法进行处理，这个字 
	 * 符串应该已经是用中文金额大写形式表示的 
	 * @param s String 已经转换好的字符串 
	 * @return 改进后的字符串 
	 */  
	private String cleanZero(String s) {  
	    // 如果传入的是空串则继续返回空串  
	    if("".equals(s)) {  
	        return "";  
	    }  
	    // 如果用户开始输入了很多 0 去掉字符串前面多余的'零'，使其看上去更符合习惯  
	    while(s.charAt(0) == '零') {  
	        // 将字符串中的 "零" 和它对应的单位去掉  
	        s = s.substring(2);  
	        // 如果用户当初输入的时候只输入了 0，则只返回一个 "零"  
	        if(s.length() == 0) {  
	            return "零";  
	        }  
	    }  
	    // 字符串中存在多个'零'在一起的时候只读出一个'零'，并省略多余的单位  
	    /* 由于本人对算法的研究太菜了，只能用4个正则表达式去转换了，各位大虾别介意哈... */  
	    String regex1[] = {"零仟", "零佰", "零拾"};  
	    String regex2[] = {"零亿", "零万", "零元"};  
	    String regex3[] = {"亿", "万", "元"};  
	    String regex4[] = {"零角", "零分"};  
	    // 第一轮转换把 "零仟", 零佰","零拾"等字符串替换成一个"零"  
	    for(int i = 0; i < 3; i ++) {  
	        s = s.replaceAll(regex1[i], "零");  
	    }  
	    // 第二轮转换考虑 "零亿","零万","零元"等情况  
	    // "亿","万","元"这些单位有些情况是不能省的，需要保留下来  
	    for(int i = 0; i < 3; i ++) {  
	        // 当第一轮转换过后有可能有很多个零叠在一起  
	        // 要把很多个重复的零变成一个零  
	        s = s.replaceAll("零零零", "零");  
	        s = s.replaceAll("零零", "零");  
	        s = s.replaceAll(regex2[i], regex3[i]);  
	    }  
	    // 第三轮转换把"零角","零分"字符串省略  
	    for(int i = 0; i < 2; i ++) {  
	        s = s.replaceAll(regex4[i], "");  
	    }  
	    // 当"万"到"亿"之间全部是"零"的时候，忽略"亿万"单位，只保留一个"亿"  
	    s = s.replaceAll("亿万", "亿");  
	    return s;  
	}
	/** 
	 * 把用户输入的数以小数点为界分割开来，并调用 numFormat() 方法 
	 * 进行相应的中文金额大写形式的转换 
	 * 注：传入的这个数应该是经过 roundString() 方法进行了四舍五入操作的 
	 * @param s String 
	 * @return 转换好的中文金额大写形式的字符串 
	 */  
	private String splitNum(String s) {
		// 如果传入的是空串则继续返回空串
		if ("".equals(s)) {
			return "";
		}
		// 以小数点为界分割这个字符串
		int index = s.indexOf(".");
		// 截取并转换这个数的整数部分
		String intOnly = s.substring(0, index);
		String part1 = this.numFormat(1, intOnly);
		// 截取并转换这个数的小数部分
		String smallOnly = s.substring(index + 1);
		String part2 = this.numFormat(2, smallOnly);
		// 把转换好了的整数部分和小数部分重新拼凑一个新的字符串
		String newS = part1 + part2;
		return newS;
	}
	/** 
	 * 把传入的数转换为中文金额大写形式 
	 * @param flag int 标志位，1 表示转换整数部分，0 表示转换小数部分 
	 * @param s String 要转换的字符串 
	 * @return 转换好的带单位的中文金额大写形式 
	 */  
	private String numFormat(int flag, String s) {  
	    int sLength = s.length();  
	    // 货币大写形式  
	    String bigLetter[] = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};  
	    // 货币单位  
	    String unit[] = {"元", "拾", "佰", "仟", "万",   
	            // 拾万位到仟万位  
	            "拾", "佰", "仟",  
	            // 亿位到万亿位  
	            "亿", "拾", "佰", "仟", "万"};  
	    String small[] = {"分", "角"};  
	    // 用来存放转换后的新字符串  
	    String newS = "";  
	    // 逐位替换为中文大写形式  
	    for(int i = 0; i < sLength; i ++) {  
	        if(flag == 1) {  
	            // 转换整数部分为中文大写形式（带单位）  
	            newS = newS + bigLetter[s.charAt(i) - 48] + unit[sLength - i - 1];  
	        } else if(flag == 2) {  
	            // 转换小数部分（带单位）  
	            newS = newS + bigLetter[s.charAt(i) - 48] + small[sLength - i - 1];  
	        }  
	    }  
	    return newS;  
	}  
	/** 
	 * 对传入的数进行四舍五入操作 
	 * @param s String 从命令行输入的那个数 
	 * @return 四舍五入后的新值 
	 */  
	private String roundString(String s) {  
	    // 如果传入的是空串则继续返回空串  
	    if("".equals(s)) {  
	        return "";  
	    }  
	    // 将这个数转换成 double 类型，并对其进行四舍五入操作  
	    double d = Double.parseDouble(s);  
	    // 此操作作用在小数点后两位上  
	    d = (d * 100 + 0.5) / 100;  
	    // 将 d 进行格式化  
	    s = new java.text.DecimalFormat("##0.000").format(d);  
	    // 以小数点为界分割这个字符串  
	    int index = s.indexOf(".");  
	    // 这个数的整数部分  
	    String intOnly = s.substring(0, index);  
	    // 规定数值的最大长度只能到万亿单位，否则返回 "0"  
	    if(intOnly.length() > 13) {  
	        System.out.println("输入数据过大！（整数部分最多13位！）");  
	        return "";  
	    }  
	    // 这个数的小数部分  
	    String smallOnly = s.substring(index + 1);  
	    // 如果小数部分大于两位，只截取小数点后两位  
	    if(smallOnly.length() > 2) {  
	        String roundSmall = smallOnly.substring(0, 2);  
	        // 把整数部分和新截取的小数部分重新拼凑这个字符串  
	        s = intOnly + "." + roundSmall;  
	    }  
	    return s;  
	}  	
	/**   
	 * reason   
	 *   
	 * @return the reason   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getReason() {
		return reason;
	}

	/**   
	 * @param reason the reason to set   
	 */
	public void setReason(String reason) {
		this.reason = GwkDB.convert_chn(reason);
	}

	/**   
	 * bdgagencyname   
	 *   
	 * @return the bdgagencyname   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getBdgagencyname() {
		return bdgagencyname;
	}

	/**   
	 * @param bdgagencyname the bdgagencyname to set   
	 */
	public void setBdgagencyname(String bdgagencyname) {
		this.bdgagencyname = bdgagencyname;
	}

	/**   
	 * funcname   
	 *   
	 * @return the funcname   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getFuncname() {
		return funcname;
	}

	/**   
	 * @param funcname the funcname to set   
	 */
	public void setFuncname(String funcname) {
		this.funcname = funcname;
	}


	/**   
	 * message   
	 *   
	 * @return the message   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getMessage() {
		return message;
	}

	/**   
	 * @param message the message to set   
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**   
	 * result   
	 *   
	 * @return the result   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getResult() {
		return result;
	}

	/**   
	 * @param result the result to set   
	 */
	public void setResult(String result) {
		this.result = result;
	}

	/**   
	 * 此方法描述的是： 支付确认、退票、退款
	 * @author: 朱凯锋   
	 * @param: flag=0,确认 flag=1，退票
	 * @version: 2013年10月9日 下午4:53:47   
	 * @throws Throwable 
	 */
	public void Comfirm(int flag) throws Throwable {
		String[] spar = new String[6];
    	spar[0] = "BANK.BOC"; 
    	spar[1] = "006"; 
        SimpleDateFormat year = new SimpleDateFormat("yyyy");//设置日期格式
        spar[2] = year.format(new Date()).toString(); 
        //System.out.println("setyear:"+spar[2].toString());
        spar[3] = "450300"; 
        spar[4] = " "; 
        spar[5] = billtype; 

    	String[] slist = new String[12];

    	slist[0]="actiontype";
    	if(flag==0)
    		slist[1]="02";
    	else if(flag==1)
    		slist[1]="03";
    	else if(flag==2)
    		slist[1]="06";
    	else if(flag==3)
    		slist[1]="02";
    	else{
    		throw new Exception("Error flag");
    	}
    	slist[2]="reason";
    	slist[3]= new String(reason.getBytes("gb2312"), "iso8859-1");
    	slist[4]="amt";
    	slist[5]=total;
    	slist[6]="billcode";
    	slist[7]=billcode;
    	slist[8]="operator";
    	slist[9]="";
    	slist[10]="operatetime";
    	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
    	slist[11]=df.format(new Date()).toString();
    	SimpleDateFormat df1 = new SimpleDateFormat("yyyy/MM/dd");
    	setTranstime(df1.format(new Date()).toString());
    	
        openConnection();
        String req = request("replyAutAllPayAccreditVou",spar,1,slist);
        System.out.println("Comfirm request:"+req);
        String signed = signfile(req);
        OutputStream os = conn.getOutputStream();
        os.write(signed.getBytes());
        os.flush();
        os.close();
        Thread.sleep(1200);
        String m_resp = respond();
        String respb[] = m_resp.split("</casign>");
        System.out.println("c DEBUG length:" + Integer.toString(respb.length));
        if(respb.length<2){
        	Thread.sleep(800);
        	m_resp += respond();
            respb = m_resp.split("</casign>");
	    }
        ResStream(respb[1]);

        // 断开连接
        conn.disconnect();
    	if(result.equalsIgnoreCase("success")){
    		if(flag==0||flag==3){
	   			try {
					comfirmtoDB(flag);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
				} catch (IOException e) {
					// TODO Auto-generated catch block
				}
			}else if(flag==2){
	   			try {
					updateDB(flag);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
				} catch (IOException e) {
					// TODO Auto-generated catch block
				}
        	}
        }
	}
	/**   
	 * 此方法描述的是： 支付凭证查询（单号查询）
	 * @author: 朱凯锋   
	 * @version: 2013年9月26日 下午6:01:24   
	 * @param: billcode-凭证号
	 * @throws Throwable 
	 */
    public void BillQuery() throws Throwable{
    	String[] spar = new String[7];
    	
    	spar[0] = "BANK.BOC"; 
    	spar[1] = "006"; 
        SimpleDateFormat year = new SimpleDateFormat("yyyy");//设置日期格式
        spar[2] = year.format(new Date()).toString(); 
        spar[3] = "450300"; 
        spar[4] = " "; 
        spar[5] = billtype; 
        spar[6] = billcode; 
        
        openConnection();
        String req = request("queryVoucherByBillCode",spar,0,null);
        System.out.println("request:"+req);
        String signed = signfile(req);
        //System.out.println("signed:"+signed);
        OutputStream os = conn.getOutputStream();
        os.write(signed.getBytes());
        os.flush();
        os.close();
        Thread.sleep(1200);
	    String m_resp = respond();
        String respb[] = m_resp.split("</casign>");
        System.out.println("DEBUG length:" + Integer.toString(respb.length));
        if(respb.length<2){
        	Thread.sleep(800);
        	m_resp += respond();
            respb = m_resp.split("</casign>");
	    }
        RespBillQuery(respb[1]);
        // 断开连接
        conn.disconnect();		
    }
    
    /**   
     * 此方法描述的是： 连接到财政局service
     * @author: 朱凯锋   
     * @version: 2013年9月28日 下午6:10:06   
     * @throws IOException 
     */
    
    private void openConnection() throws IOException {
    	GwkDB db = new GwkDB();
    	String GL_Service = db.GetPrivateProfileString("GL_SERVICE","http://10.10.10.7:9099/exserver/remoting/bankservice");
    	URL getUrl = new URL(GL_Service);
    	conn = (HttpURLConnection) getUrl.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.connect();
        //conn.setRequestProperty("Content-Type", "x-application/burlap");
    }

    private String request(String Method,String[] par,int llen,String[] slist) throws IOException, InterruptedException{
    	//OutputStream os = conn.getOutputStream();
    	//OutputStream os = new FileOutputStream("r:\\request.xml");
    	String restring = new String();
    	OutputStream os = new ByteArrayOutputStream();
        BurlapOutput bo = new BurlapOutput(os);
        bo.startCall(Method);  // start  call
        for(int i=0;i<par.length;i++){
        	if(par[i].length()==0){
        		bo.writeNull();
        	}else
        		bo.writeString(par[i].toString());
        	//System.out.println("debug:"+par.length+"@"+i+par[i].toString());
        }
        if(llen>0){
        	bo.writeListBegin(llen, "");
        	bo.writeMapBegin("");
        	for(int i=0;i<slist.length;i++){
        		if(slist[i].length()==0)
        			bo.writeNull();
        		else
        			bo.writeString(slist[i].toString());
        		//System.out.println(slist[i].toString());
        	}
        	bo.writeMapEnd();
        	bo.writeListEnd();
        }
        bo.completeCall();      // complete the call
        bo.flush();
        bo.close();
        restring = os.toString();
        os.close();
		return restring;
    }
    /*
    private void respond() throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8"));//设置编码,否则中文乱码
        System.out.println("=============================");
        String lines;
        while ((lines = reader.readLine()) != null){
        	lines = new String(lines.getBytes("utf-8"),"gb2312");
            System.out.println(lines);
        }
        reader.close();
    }*/

	/**   
	 * billcode   
	 *   
	 * @return the billcode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getBillcode() {
		return billcode;
	}

	/**   
	 * @param billcode the billcode to set   
	 */
	public void setBillcode(String billcode) {
		init();
		this.billcode = billcode;
		try {
			BillQuery();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**   
	 * printid   
	 *   
	 * @return the printid   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPrintid() {
		return printid;
	}

	/**   
	 * @param printid the printid to set   
	 */
	public void setPrintid(String printid) {
		this.printid = printid;
	}

	/**   
	 * createdate   
	 *   
	 * @return the createdate   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getCreatedate() {
		return createdate;
	}

	/**   
	 * @param createdate the createdate to set   
	 */
	public void setCreatedate(String createdate) {
		this.createdate = createdate;
	}

	/**   
	 * clearbankname   
	 *   
	 * @return the clearbankname   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getClearbankname() {
		return clearbankname;
	}

	/**   
	 * @param clearbankname the clearbankname to set   
	 */
	public void setClearbankname(String clearbankname) {
		this.clearbankname = clearbankname;
	}

	/**   
	 * clearbankcode   
	 *   
	 * @return the clearbankcode   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getClearbankcode() {
		return clearbankcode;
	}

	/**   
	 * @param clearbankcode the clearbankcode to set   
	 */
	public void setClearbankcode(String clearbankcode) {
		this.clearbankcode = clearbankcode;
	}

	/**   
	 * paybankaccount   
	 *   
	 * @return the paybankaccount   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPaybankaccount() {
		return paybankaccount;
	}

	/**   
	 * @param paybankaccount the paybankaccount to set   
	 */
	public void setPaybankaccount(String paybankaccount) {
		this.paybankaccount = paybankaccount;
	}

	/**   
	 * pay   
	 *   
	 * @return the pay   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPay() {
		return pay;
	}

	/**   
	 * @param pay the pay to set   
	 */
	public void setPay(String pay) {
		this.pay = pay;
	}

	/**   
	 * paybank   
	 *   
	 * @return the paybank   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPaybank() {
		return paybank;
	}

	/**   
	 * @param paybank the paybank to set   
	 */
	public void setPaybank(String paybank) {
		this.paybank = paybank;
	}

	/**   
	 * payeebankaccount   
	 *   
	 * @return the payeebankaccount   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPayeebankaccount() {
		return payeebankaccount;
	}

	/**   
	 * @param payeebankaccount the payeebankaccount to set   
	 */
	public void setPayeebankaccount(String payeebankaccount) {
		this.payeebankaccount = payeebankaccount;
	}

	/**   
	 * payee   
	 *   
	 * @return the payee   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPayee() {
		return payee;
	}

	/**   
	 * @param payee the payee to set   
	 */
	public void setPayee(String payee) {
		this.payee = payee;
	}

	/**   
	 * payeebank   
	 *   
	 * @return the payeebank   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPayeebank() {
		return payeebank;
	}

	/**   
	 * @param payeebank the payeebank to set   
	 */
	public void setPayeebank(String payeebank) {
		this.payeebank = payeebank;
	}

	/**   
	 * amt   
	 *   
	 * @return the amt   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getAmt(int x) {
		return amt[x];
	}

	/**   
	 * @param amt the amt to set   
	 */
	public void setAmt(int index,String amt) {
		this.amt[index] = AmtFormat(amt);
	}
	
	
	/**   
	 * 此方法描述的是： 转换成金额格式
	 * @author: 朱凯锋   
	 * @version: 2013年11月12日 上午10:41:39   
	 */
	private String AmtFormat(String s){
		int index = s.indexOf(".");
		if(index<0){
			s += ".00";
			return s;
		}else{
			String jf = s.substring(index+1);
			if(jf.length()==1)
				s += "0";
			return s;
		}
		
		/*
		// 截取并转换这个数的整数部分
		String part1 = s.substring(0, index);
		// 截取并转换这个数的小数部分
		String smallOnly = s.substring(index + 1);
		String part2 = this.numFormat(2, smallOnly);
		// 把转换好了的整数部分和小数部分重新拼凑一个新的字符串
		String newS = part1 + part2;
		return newS;
		*/		
	}
	/**   
	 * departmentname   
	 *   
	 * @return the departmentname   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getDepartmentname() {
		return departmentname;
	}

	/**   
	 * @param departmentname the departmentname to set   
	 */
	public void setDepartmentname(String departmentname) {
		this.departmentname = departmentname;
	}

	/**   
	 * expfunc   
	 *   
	 * @return the expfunc   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getExpfunc() {
		return expfunc;
	}

	/**   
	 * @param expfunc the expfunc to set   
	 */
	public void setExpfunc(String expfunc) {
		this.expfunc = expfunc;
	}

	/**   
	 * expeco   
	 *   
	 * @return the expeco   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getExpeco() {
		return expeco;
	}

	/**   
	 * @param expeco the expeco to set   
	 */
	public void setExpeco(String expeco) {
		this.expeco = expeco;
	}

	/**   
	 * program   
	 *   
	 * @return the program   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getProgram() {
		return program;
	}

	/**   
	 * @param program the program to set   
	 */
	public void setProgram(String program) {
		this.program = program;
	}

	/**   
	 * paykind   
	 *   
	 * @return the paykind   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getPaykind() {
		return paykind;
	}

	/**   
	 * @param paykind the paykind to set   
	 */
	public void setPaykind(String paykind) {
		this.paykind = paykind;
	}

	/**   
	 * remark   
	 *   
	 * @return the remark   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getRemark() {
		return remark;
	}

	/**   
	 * @param remark the remark to set   
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**   
	 * guid   
	 *   
	 * @return the guid   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getGuid() {
		return guid;
	}

	/**   
	 * @param guid the guid to set   
	 */
	public void setGuid(String guid) {
		this.guid = guid;
	}

	/**   
	 * vouchertype   
	 *   
	 * @return the vouchertype   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getVouchertype() {
		return vouchertype;
	}

	/**   
	 * @param vouchertype the vouchertype to set   
	 */
	public void setVouchertype(String vouchertype) {
		this.vouchertype = vouchertype;
	}

	/**   
	 * account   
	 *   
	 * @return the account   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getAccount(int x) {
		return account[x];
	}

	/**   
	 * @param account the account to set   
	 */
	public void setAccount(int x,String account) {
		this.account[x] = account;
	}

	/**   
	 * cardname   
	 *   
	 * @return the cardname   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getCardname(int x) {
		return cardname[x];
	}

	/**   
	 * @param cardname the cardname to set   
	 */
	public void setCardname(int x,String cardname) {
		this.cardname[x] = cardname;
	}

	/**   
	 * fundtype   
	 *   
	 * @return the fundtype   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getFundtype() {
		return fundtype;
	}

	/**   
	 * @param fundtype the fundtype to set   
	 */
	public void setFundtype(String fundtype) {
		this.fundtype = fundtype;
	}

	/**   
	 * programname   
	 *   
	 * @return the programname   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getProgramname() {
		return programname;
	}

	/**   
	 * @param programname the programname to set   
	 */
	public void setProgramname(String programname) {
		this.programname = programname;
	}

	/**   
	 * bdgmanagedivision   
	 *   
	 * @return the bdgmanagedivision   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getBdgmanagedivision() {
		return bdgmanagedivision;
	}

	/**   
	 * @param bdgmanagedivision the bdgmanagedivision to set   
	 */
	public void setBdgmanagedivision(String bdgmanagedivision) {
		this.bdgmanagedivision = bdgmanagedivision;
	}

	/**   
	 * indsource   
	 *   
	 * @return the indsource   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getIndsource() {
		return indsource;
	}

	/**   
	 * @param indsource the indsource to set   
	 */
	public void setIndsource(String indsource) {
		this.indsource = indsource;
	}

	/**   
	 * profund   
	 *   
	 * @return the profund   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getProfund() {
		return profund;
	}

	/**   
	 * @param profund the profund to set   
	 */
	public void setProfund(String profund) {
		this.profund = profund;
	}

	/**   
	 * cleartag   
	 *   
	 * @return the cleartag   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getCleartag() {
		return cleartag;
	}

	/**   
	 * @param cleartag the cleartag to set   
	 */
	public void setCleartag(String cleartag) {
		this.cleartag = cleartag;
	}

	/**   
	 * wfstatus   
	 *   
	 * @return the wfstatus   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public String getWfstatus() {
		return wfstatus;
	}

	/**   
	 * @param wfstatus the wfstatus to set   
	 */
	public void setWfstatus(String wfstatus) {
		this.wfstatus = wfstatus;
		if(wfstatus.equalsIgnoreCase("31")){
			this.wfstatus +="-银行支付";
		}else if(wfstatus.equalsIgnoreCase("96")){
			this.wfstatus +="-财政发送";
		}
		if(wfstatus.equalsIgnoreCase("99")){
			this.wfstatus +="-银行退票";
		}
	}
	
	private void setTagValue(String Tag,String Value){
		if(Tag.equals("printid")){//凭证编号
			setPrintid(Value);
		}else if(Tag.equals("createdate")){//凭证日期
			setCreatedate(Value);
		} else if (Tag.equals("paybankaccount")) {// 付款人账号
			setPaybankaccount(Value);
		} else if (Tag.equals("pay")) {// 付款人全称
			setPay(Value);
		} else if (Tag.equals("paybank")) {// 付款人开户银行
			setPaybank(Value);
		} else if (Tag.equals("payeebankaccount")) {// 收款人账号
			setPayeebankaccount(Value);
		} else if (Tag.equals("payee")) {// 收款人全称
			setPayee(Value);
		} else if (Tag.equals("payeebank")) {// 收款人开户行
			setPayeebank(Value);
		} else if (Tag.equals("amt")) {// 金额
			 setTotal(Value);
		} else if (Tag.equals("departmentname")) {// 一级预算单位
			setDepartmentname(Value);
		} else if (Tag.equals("expfunc")) {// 支出功能分类
			setExpfunc(Value);
		} else if (Tag.equals("expeco")) {// 支出经济分类
			setExpeco(Value);
		} else if (Tag.equals("program")) {// 项目
			setProgram(Value);
		} else if (Tag.equals("paykind")) {// 支出类型
			setPaykind(Value);
		} else if (Tag.equals("remark")) {// 摘要
			setRemark(Value);
		} else if (Tag.equals("guid")) {// 凭证唯一标识
			setGuid(Value);
		} else if (Tag.equals("vouchertype")) {// 凭证类型
			setVouchertype(Value);
		} else if (Tag.equals("account")) {// 卡号
			// setAccount(Value);
		} else if (Tag.equals("cardname")) {// 持卡人
			// setCardname(Value);
		} else if (Tag.equals("fundtype")) {// 资金性质
			setFundtype(Value);
		} else if (Tag.equals("programname")) {// 项目名称
			setProgramname(Value);
		} else if (Tag.equals("bdgmanagedivision")) {// 归口处室
			setBdgmanagedivision(Value);
		} else if (Tag.equals("indsource")) {// 预算来源
			setIndsource(Value);
		} else if (Tag.equals("profund")) {// 项目归类
			setProfund(Value);
		} else if (Tag.equals("cleartag")) {// 清算标识
			setCleartag(Value);
		} else if (Tag.equals("wfstatus")) {// 状态标识
			setWfstatus(Value);
		} else if (Tag.equals("message")) {// 状态标识
			setMessage(Value);
		} else if (Tag.equals("result")) {// 状态标识
			setResult(Value);
		} else if (Tag.equals("funcname")) {// 功能分类科目名称
			setFuncname(Value);
		} else if (Tag.equals("bdgagencyname")) {// 单位名称
			setBdgagencyname(Value);
		} else if (Tag.equals("expecocode")) {// 支出经济分类科目编码
			setExpecocode(Value);
		} else if (Tag.equals("paytypecode")) {//支付方式编码
			setPaytypecode(Value);
		} else if (Tag.equals("programcode")) {//项目类别编码
			setProgramcode(Value);
		} else if (Tag.equals("settlmodecode")) {//付款方式编码
			setSettlmodecode(Value);
		} else if (Tag.equals("expeconame")) {//支出经济分类科目名称
			setExpeconame(Value);
		} else if (Tag.equals("paybankcode")) {//付款银行编码
			setPaybankcode(Value);
		} else if (Tag.equals("fundtypename")) {//资金性质名称
			setFundtypename(Value);
		} else if (Tag.equals("clearbankname")) {//清算银行名称
			setClearbankname(Value);
		} else if (Tag.equals("clearbankcode")) {//清算银行名称
			setClearbankcode(Value);
		} else if (Tag.equals("departmentcode")) {//上级单位编码
			setDepartmentcode(Value);
		} else if (Tag.equals("funccode")) {//功能分类科目编码
			setFunccode(Value);
		} else if (Tag.equals("bdgagencycode")) {//单位编码
			setBdgagencycode(Value);
		} else if (Tag.equals("sendtime")) {//最后操作时间
			setSendtime(Value);
		} else if (Tag.equals("settlmodename")) {//付款方式名称
			setSettlmodename(Value);
		} else if (Tag.equals("paytypename")) {//支付方式名称
			setPaytypename(Value);
		} else if (Tag.equals("billid")) {//billid
			setBillid(Value);
		} else if (Tag.equals("fundtypecode")) {//资金性质编码
			setFundtypecode(Value);
		} else if (Tag.equals("oldbillcode")) {//被退款凭证
			setOldbillcode(Value);
		} else if (Tag.equals("billcode")) {//凭证
			this.billcode = Value;
		} else if (Tag.equals("tkreason")) {//退款原因
			setTkreason(Value);
		} else if (Tag.equals("tpreason")) {//退票原因
			setTpreason(Value);
		} else{
			System.out.println("Not defined:[" + Tag + "]" + Value);
		}
		
	}
	
	private void RespBillQuery(String indate) throws Throwable {
		System.out.println("RespBillQuery:" + indate);
		InputStream is = new ByteArrayInputStream(indate.getBytes("utf-8"));
		BurlapInput bi = new BurlapInput(is);
		//截取casign
        bi.startReply();         // read reply header
        bi.readListStart();
        bi.readType();
        bi.readLength();
        bi.readMapStart();
        bi.readType();
        while(!bi.isEnd()){
        	String tagname = bi.readString();
        	if(tagname.equals("details")){
        		//do it details
        		bi.readListStart();
        		bi.readType();
                details = bi.readLength();
                amt = new String[details];
                account = new String[details];
                cardname = new String[details];
                for(int i=0;i<details;i++){
                    bi.readMapStart();
                    bi.readType();
                    for(int j=0;j<3;j++){
	                	tagname = bi.readString();
	                	String value = bi.readString();
	                	if(tagname.equals("amt")){
	                		setAmt(i,value);
	                	}else if(tagname.equals("cardname")){
	                		setCardname(i,value);
	                	}else if(tagname.equals("account")){
	                		setAccount(i,value);
	                	}
                    }
                    bi.readMapEnd();
                }
                bi.readListEnd();
        	}else{
        		String value = bi.readString();
        		if(value != null){
        			setTagValue(tagname,value);
        			//System.out.println(tagname + " is: " + value );
        		}
        		//System.out.println(tagname + " is: " + value );
        	}
        }
        bi.readMapEnd();
        bi.readMapStart();
        bi.readType();
        for(int i=0;i<2;i++){
	        String tagname = bi.readString();
	        String value = bi.readString();
			if(value != null){
				setTagValue(tagname,value);
			}
			System.out.println(tagname + " is: " + value );
        }
        bi.readMapEnd();
        bi.readListEnd();
        bi.completeReply();      // read reply footer
        bi.close();
        is.close();
	}

	private void ResStream(String indate) throws Throwable{
		System.out.println("ResStream:" + indate);
		InputStream is = new ByteArrayInputStream(indate.getBytes("utf-8"));
		BurlapInput bi = new BurlapInput(is);

        bi.startReply();         // read reply header
        bi.readListStart();
        bi.readType();
        bi.readLength();
        bi.readMapStart();
        bi.readType();
        while(!bi.isEnd()){
        	String tagname = bi.readString();
       		String value = bi.readString();
       		if(value != null){
       			setTagValue(tagname,value);
       		}
       		System.out.println(tagname + " is: " + value );
        }
        bi.readMapEnd();
        bi.readListEnd();
        bi.completeReply();      // read reply footer
        bi.close();
        is.close();
	}
	/**   
	 * details   
	 *   
	 * @return the details   
	 * @since   CodingExample Ver(编码范例查看) 1.0   
	 */
	public int getDetails() {
		return details;
	}
    
    private String respond() throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"GBK"));//设置编码,否则中文乱码
        String lines;
        String retS="";
		while ((lines = reader.readLine()) != null){
        	//lines = new String(lines.getBytes("utf-8"),"gb2312");
        	retS += lines;
        	//System.out.println(lines);
        }
        reader.close();
		return retS;
    }
    
    /*按字节读取字符串*/
    /* 个人感觉最好的方式，（一次读完）读字节就读字节吧，读完转码一次不就好了*/
    @SuppressWarnings("unused")
	private String readString3(InputStream in)
    {
        String str=null;
        try {
            //FileInputStream in=new FileInputStream(in);
            // size  为字串的长度 ，这里一次性读完
            int size=in.available();
            byte[] buffer=new byte[size];
            in.read(buffer);
            in.close();
            str=new String(buffer,"UTF-8");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return str;
    }


	private String signfile(String indate) throws IOException{
		//StringBuffer sb = new StringBuffer();
        //readToBuffer(sb, filename);
        String ca_sign = casign(indate.toString());
        /*System.out.println("ca length:" + ca_sign.length());
        System.out.println("ca:" + ca_sign);
        System.out.println("s length:" + indate.length());
        System.out.println("s:" + indate.toString());
        BufferedWriter bw = new BufferedWriter(new FileWriter("r:\\re.xml"));
        bw.write("<casign>");
        bw.write(ca_sign.toString());
        bw.write("</casign>");
        bw.write(indate.toString());
        bw.close();*/
		String res = "<casign>";
		res += ca_sign;
		res += "</casign>";
		res += indate;
		return res;
	}
	private String casign(String sign_msg){
		com.itrus.cryptorole.bc.SenderBcImpl sender = new com.itrus.cryptorole.bc.SenderBcImpl();
		GwkDB db = new GwkDB();
    	String pfxFileName = null;
		try {
			pfxFileName = db.GetPrivateProfileString("CERTFILE","/gwcard/certfile/test1.pfx");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String keyPassword = "111111";//证书密码
		String signedData = null;
		try 
		{
			System.out.println("[pfxFile]" + pfxFileName + "[keyPassword]" + keyPassword);
			sender.initCertWithKey(pfxFileName, keyPassword.toCharArray());
			byte[] p7 = sender.signMessage(sign_msg.getBytes());
			signedData = new String(Base64.encode(p7));//签名结果值
		} 
		catch (NotSupportException e) 
		{
			e.printStackTrace();
		} catch (CryptoException e) 
		{
			e.printStackTrace();
		}
		return signedData;
	}
	private void comfirmtoDB(int flag) throws SQLException, IOException{
		GwkDB gwkdb = new GwkDB();
		String mysql = "insert into GX_CORP_GL_PAYBILL(BILLCODE,total,"
				+ "paybankaccount,pay,USR_ID,UPD_DATE,FLAG) ";
		mysql += "values(\'" + billcode + "\',\'";
		mysql += total + "\',\'";
		mysql += paybankaccount + "\',\'";
		mysql += pay + "\',\'";
		mysql += user_id + "\',sysdate,";
		mysql += Integer.toString(flag) + ")";
		gwkdb.update(mysql);
	}
	private void updateDB(int flag) throws SQLException, IOException{
		GwkDB gwkdb = new GwkDB();
		String mysql = "update GX_CORP_GL_PAYBILL ";
		mysql += "set flag=" + Integer.toString(flag);
		mysql += ",vbillcode='" + billcode +"' ";
		mysql += "where billcode='" + oldbillcode + "' ";
		gwkdb.update(mysql);
	}
	private void VgetOrg(){
		String mysql = "select to_char(total,'99999999.99'),to_char(upd_date,'yyyy/mm/dd') " +
					"from GX_CORP_GL_PAYBILL ";
		mysql += "where billcode='" + oldbillcode +"' ";
		GwkDB gwkdb = new GwkDB();
		int ret;
		try {
			ret = gwkdb.query(mysql, 2);
			if(ret<0)return;
			if(gwkdb.dbvt.size()<1)return;
			orgtotal = gwkdb.dbvt.get(0).get(0).toString();
			orgdate = gwkdb.dbvt.get(0).get(1).toString();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
		} catch (IOException e) {
			// TODO Auto-generated catch block
		}
	}
}
